<template>
  <div class="company-list-1">
    <div class="header">
      <div class="prefix"></div>
      <div class="header-title">精准巡查概览</div>
    </div>
    <div class="content">
      <div style="width: 100%; height: 200px">
        <MyEchart :option="dataSource"></MyEchart>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref, computed, watchEffect} from 'vue'
import MyEchart from '@/components/echarts/MyCharts2.vue'

const props = defineProps({
  info: {
    type: Array,
    required: false,
    default: () => []
  }
})

const dataSource = ref()
const eventType = computed(() => {
  if (!props.info || !Array.isArray(props.info)) return []
  return props.info.map((item) => ({name: item.eventType, value: item.count}))
})

watchEffect(() => {
  dataSource.value = {
    tooltip: {trigger: 'item'},
    series: [
      {
        type: 'pie',
        radius: '65%',
        center: ['50%', '50%'],
        data: eventType.value,
        label: {
          show: true,
          position: 'outside',
          color: '#fff',
          fontSize: 16
        },
        labelLine: {
          show: true
        }
      },
      {
        type: 'pie',
        data: eventType.value,
        label: {
          show: true,
          position: 'inside',
          formatter: `{d}%`
        }
      }
    ]
  }
})
</script>

<style scoped lang="scss">
@import '@/assets/table.css';

.company-list-1 {
  padding: 10px;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  font-size: 16px;

  .header {
    width: 350px;
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 20px;

    .prefix {
      width: 8px;
      height: 15px;
      background-color: #31a7ff;
    }

    .header-title {
      padding-left: 10px;
    }
  }

  .content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
  }
}
</style>
